/*
 * Copyright (c) 2015 Messcat. All rights reserved.
 */
package cc.messcat.entity.system;

import cc.messcat.common.model.views.Views;
import cc.messcat.common.util.DateHelper;
import cc.messcat.entity.area.Area;
import cc.messcat.entity.level.UserLevel;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import com.fasterxml.jackson.annotation.JsonView;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.*;
import javax.validation.constraints.Max;
import java.util.Set;

/**
 * 用户实体
 *
 * @author Microcat
 * @version 1.0
 */
@Entity
@Table(name = "MC_USER")
@SuppressWarnings("serial")
public class McUser implements java.io.Serializable {

    public interface WithoutPasswordView extends Views {
    }

    @JsonView(WithoutPasswordView.class)
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "ID")
    private Long id;

    @JsonView(WithoutPasswordView.class)
    @Column(name = "USERNAME", length = 50)
    private String username;

    @JsonIgnore
    @Column(name = "PASSWORD", length = 50)
    private String password;

    @JsonView(WithoutPasswordView.class)
    @Column(name = "NICK_NAME", length = 20)
    private String nickName;

    @JsonView(WithoutPasswordView.class)
    @Column(name = "MOBILE_PHONE", length = 20)
    private String mobilePhone;

    @Column(name = "REAL_NAME", length = 20)
    private String realName;

    @Column(name = "EMAIL", length = 50)
    private String email;
    
    //用户类型,分别：管理员，政府人员，帮扶人员，贫困户
    @Column(name="TYPE",length=60)
    private String type;

    @Max(value = 20)
    @Column(name = "LOGIN_COUNT")
    private int loginCount;

    @DateTimeFormat(pattern = DateHelper.DATE_COMMON_FORMAT)
    @Column(name = "LAST_LOGIN")
    private java.util.Date lastLogin;

    @DateTimeFormat(pattern = DateHelper.DATE_COMMON_FORMAT)
    @Column(name = "EDIT_TIME")
    private java.util.Date editTime;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "EDITOR")
    @JsonIgnore
    private McUser editor;

    @JsonView(WithoutPasswordView.class)
    @Column(name = "STATUS", length = 1)
    private String status;

    @Column(name = "province_id")
    private Long provinceId;//所在县ID

    @Column(name = "city_id")
    private Long cityId;//所在县ID

    @Column(name = "county_id")
    private Long countyId;//所在县ID

    @Column(name = "country_id")
    private Long countryId;//所在乡ID

    @Column(name = "village_id")
    private Long villageId;//所在村ID

    @Column(name = "province")
    private String province;//城市

    @Column(name = "city")
    private String city;//城市

    @Column(name = "cry")
    private String cry;//镇

    @Column(name = "cty")
    private String cty;//县

    @Column(name = "name")
    private String name;//所在村

    @JsonManagedReference
    @ManyToMany(cascade = CascadeType.PERSIST, fetch = FetchType.LAZY)
    @JoinTable(name = "USERS_ROLES", joinColumns = @JoinColumn(name = "USER_ID"), inverseJoinColumns = @JoinColumn(name = "ROLE_ID"))
    private Set<Role> roles;

    @ManyToOne
    @JoinColumn(name = "user_level")
    private UserLevel userLevel;// 用户等级

    private Long areaId;// 区域ID

    @Column(name = "REMARKS")
    private String remarks;//备注

    @ManyToOne(cascade = CascadeType.PERSIST,fetch = FetchType.EAGER)
    @JoinColumn(name = "area")
    private Area area;
    
    @Column(name = "AREACODES")
    private String areaCodes;//行政编号
    
    @Column(name="check_state")
    private String checkState;//审核状态 (未审核 ,已审核,审核不通过)
    
    public UserLevel getUserLevel() {
        return userLevel;
    }

    public void setUserLevel(UserLevel userLevel) {
        this.userLevel = userLevel;
    }

    public Long getAreaId() {
        return areaId;
    }

    public void setAreaId(Long areaId) {
        this.areaId = areaId;
    }

    public Area getArea() {
        return area;
    }

    public void setArea(Area area) {
        this.area = area;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getNickName() {
        return nickName;
    }

    public void setNickName(String nickName) {
        this.nickName = nickName;
    }

    public String getMobilePhone() {
        return mobilePhone;
    }

    public void setMobilePhone(String mobilePhone) {
        this.mobilePhone = mobilePhone;
    }

    public String getRealName() {
        return realName;
    }

    public void setRealName(String realName) {
        this.realName = realName;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public int getLoginCount() {
        return loginCount;
    }

    public void setLoginCount(int loginCount) {
        this.loginCount = loginCount;
    }

    public java.util.Date getLastLogin() {
        return lastLogin;
    }

    public void setLastLogin(java.util.Date lastLogin) {
        this.lastLogin = lastLogin;
    }

    public java.util.Date getEditTime() {
        return editTime;
    }

    public void setEditTime(java.util.Date editTime) {
        this.editTime = editTime;
    }

    public McUser getEditor() {
        return editor;
    }

    public void setEditor(McUser editor) {
        this.editor = editor;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public Set<Role> getRoles() {
        return roles;
    }

    public void setRoles(Set<Role> roles) {
        this.roles = roles;
    }

    public String getRemarks() {
        return remarks;
    }

    public void setRemarks(String remarks) {
        this.remarks = remarks;
    }


    public Long getProvinceId() {
        return provinceId;
    }

    public void setProvinceId(Long provinceId) {
        this.provinceId = provinceId;
    }

    public Long getCityId() {
        return cityId;
    }

    public void setCityId(Long cityId) {
        this.cityId = cityId;
    }

    public Long getCountyId() {
        return countyId;
    }

    public void setCountyId(Long countyId) {
        this.countyId = countyId;
    }

    public Long getCountryId() {
        return countryId;
    }

    public void setCountryId(Long countryId) {
        this.countryId = countryId;
    }

    public Long getVillageId() {
        return villageId;
    }

    public void setVillageId(Long villageId) {
        this.villageId = villageId;
    }

    public String getProvince() {
        return province;
    }

    public void setProvince(String province) {
        this.province = province;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getCry() {
        return cry;
    }

    public void setCry(String cry) {
        this.cry = cry;
    }

    public String getCty() {
        return cty;
    }

    public void setCty(String cty) {
        this.cty = cty;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

	public String getAreaCodes() {
		return areaCodes;
	}

	public void setAreaCodes(String areaCodes) {
		this.areaCodes = areaCodes;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getCheckState() {
		return checkState;
	}

	public void setCheckState(String checkState) {
		this.checkState = checkState;
	}
	
}
